package user

import (
	"context"
	"github.com/gogf/gf/v2/errors/gerror"
	"goAdminV1/api/user/v1"
	"goAdminV1/internal/model"
)

func (c *ControllerV1) UserLoginLog(ctx context.Context, req *v1.UserLoginLogReq) (res *v1.UserLoginLogRes, err error) {
	res = &v1.UserLoginLogRes{}

	// 调用 model 层获取登录日志列表
	data, err := model.GetUserLoginLogs(ctx, req.Limit, req.Page)
	if err != nil {
		return nil, gerror.New("获取用户登录日志时发生错误")
	}

	// 填充分页响应结构体
	res.Limit = req.Limit
	res.Total = data.Total
	res.Data = data.Logs

	return res, nil
}
